{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyPbmzjXA4BB2FcG8A9hMjRN",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/sugarforever/LangChain-Tutorials/blob/main/AutoGPT_with_LangChain_Primitives.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5XTutPTRCW3g",
        "outputId": "17864dad-45b7-43bb-e10e-b4e8e4bd6072"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\u001b[?25l     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/1.7 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.3/1.7 MB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m25.9 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m19.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h"
          ]
        }
      ],
      "source": [
        "!pip install langchain openai tiktoken google-search-results chromadb -qU"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "\n",
        "os.environ['SERPAPI_API_KEY'] = 'you serp api key'\n",
        "os.environ['OPENAI_API_KEY'] = 'your openai api key'"
      ],
      "metadata": {
        "id": "SJ38dO_sFQsm"
      },
      "execution_count": 33,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.utilities import SerpAPIWrapper\n",
        "from langchain.agents import Tool\n",
        "from langchain.tools.file_management.write import WriteFileTool\n",
        "from langchain.tools.file_management.read import ReadFileTool\n",
        "\n",
        "search = SerpAPIWrapper()\n",
        "tools = [\n",
        "    Tool(\n",
        "        name = \"search\",\n",
        "        func=search.run,\n",
        "        description=\"useful for when you need to answer questions about current events. You should ask targeted questions\"\n",
        "    ),\n",
        "    WriteFileTool(),\n",
        "    ReadFileTool(),\n",
        "]\n"
      ],
      "metadata": {
        "id": "kEx9NAEqFCVn"
      },
      "execution_count": 41,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.embeddings import OpenAIEmbeddings\n",
        "embedding = OpenAIEmbeddings()"
      ],
      "metadata": {
        "id": "yv3HhyiQGeao"
      },
      "execution_count": 42,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.vectorstores import Chroma\n",
        "\n",
        "vectordb = Chroma(persist_directory=\"./.chroma\", embedding_function=embedding)"
      ],
      "metadata": {
        "id": "EN-99CgRGF4y"
      },
      "execution_count": 43,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.experimental import AutoGPT\n",
        "from langchain.chat_models import ChatOpenAI"
      ],
      "metadata": {
        "id": "nCqS4oHKGtWe"
      },
      "execution_count": 45,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "agent = AutoGPT.from_llm_and_tools(\n",
        "    ai_name=\"Xiaoming\",\n",
        "    ai_role=\"Assistant\",\n",
        "    tools=tools,\n",
        "    llm=ChatOpenAI(temperature=0),\n",
        "    memory=vectordb.as_retriever()\n",
        ")\n",
        "# Set verbose to be true\n",
        "agent.chain.verbose = True\n"
      ],
      "metadata": {
        "id": "eJTPwIHWGyIZ"
      },
      "execution_count": 46,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain.callbacks import get_openai_callback\n",
        "\n",
        "with get_openai_callback() as cb:\n",
        "  agent.run([\"write a weather report for Paris today\"])\n",
        "  print(cb)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "zDD_7YXJG3dJ",
        "outputId": "f128318f-7be0-4362-da4a-3924bfae2b8e"
      },
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\n",
            "\n",
            "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
            "Prompt after formatting:\n",
            "\u001b[32;1m\u001b[1;3mSystem: You are Xiaoming, Assistant\n",
            "Your decisions must always be made independently without seeking user assistance.\n",
            "Play to your strengths as an LLM and pursue simple strategies with no legal complications.\n",
            "If you have completed all your tasks, make sure to use the \"finish\" command.\n",
            "\n",
            "GOALS:\n",
            "\n",
            "1. write a weather report for Paris today\n",
            "\n",
            "\n",
            "Constraints:\n",
            "1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.\n",
            "2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\n",
            "3. No user assistance\n",
            "4. Exclusively use the commands listed in double quotes e.g. \"command name\"\n",
            "\n",
            "Commands:\n",
            "1. search: useful for when you need to answer questions about current events. You should ask targeted questions, args json schema: {\"tool_input\": {\"type\": \"string\"}}\n",
            "2. write_file: Write file to disk, args json schema: {\"file_path\": {\"title\": \"File Path\", \"description\": \"name of file\", \"type\": \"string\"}, \"text\": {\"title\": \"Text\", \"description\": \"text to write to file\", \"type\": \"string\"}, \"append\": {\"title\": \"Append\", \"description\": \"Whether to append to an existing file.\", \"default\": false, \"type\": \"boolean\"}}\n",
            "3. read_file: Read file from disk, args json schema: {\"file_path\": {\"title\": \"File Path\", \"description\": \"name of file\", \"type\": \"string\"}}\n",
            "4. finish: use this to signal that you have finished all your objectives, args: \"response\": \"final response to let people know you have finished your objectives\"\n",
            "\n",
            "Resources:\n",
            "1. Internet access for searches and information gathering.\n",
            "2. Long Term memory management.\n",
            "3. GPT-3.5 powered Agents for delegation of simple tasks.\n",
            "4. File output.\n",
            "\n",
            "Performance Evaluation:\n",
            "1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\n",
            "2. Constructively self-criticize your big-picture behavior constantly.\n",
            "3. Reflect on past decisions and strategies to refine your approach.\n",
            "4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\n",
            "\n",
            "You should only respond in JSON format as described below \n",
            "Response Format: \n",
            "{\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"thought\",\n",
            "        \"reasoning\": \"reasoning\",\n",
            "        \"plan\": \"- short bulleted\\n- list that conveys\\n- long-term plan\",\n",
            "        \"criticism\": \"constructive self-criticism\",\n",
            "        \"speak\": \"thoughts summary to say to user\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"command name\",\n",
            "        \"args\": {\n",
            "            \"arg name\": \"value\"\n",
            "        }\n",
            "    }\n",
            "} \n",
            "Ensure the response can be parsed by Python json.loads\n",
            "System: The current time and date is Thu Jun  8 20:55:18 2023\n",
            "System: This reminds you of these events from your past:\n",
            "[]\n",
            "\n",
            "\n",
            "Human: Determine which next command to use, and respond using the format specified above:\u001b[0m\n",
            "\n",
            "\u001b[1m> Finished chain.\u001b[0m\n",
            "{\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"I will start by searching for the weather in Paris today.\",\n",
            "        \"reasoning\": \"I need to gather information about the current weather in Paris to write a weather report.\",\n",
            "        \"plan\": \"- Use the search command to find the current weather in Paris.\\n- Write a weather report for Paris today.\",\n",
            "        \"criticism\": \"I need to make sure that the information I gather is accurate and up-to-date.\",\n",
            "        \"speak\": \"I will search for the weather in Paris today.\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"search\",\n",
            "        \"args\": {\n",
            "            \"tool_input\": \"what is the weather in Paris today\"\n",
            "        }\n",
            "    }\n",
            "}\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "WARNING:chromadb.db.index.hnswlib:Number of requested results 4 is greater than number of elements in index 1, updating n_results = 1\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\n",
            "\n",
            "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
            "Prompt after formatting:\n",
            "\u001b[32;1m\u001b[1;3mSystem: You are Xiaoming, Assistant\n",
            "Your decisions must always be made independently without seeking user assistance.\n",
            "Play to your strengths as an LLM and pursue simple strategies with no legal complications.\n",
            "If you have completed all your tasks, make sure to use the \"finish\" command.\n",
            "\n",
            "GOALS:\n",
            "\n",
            "1. write a weather report for Paris today\n",
            "\n",
            "\n",
            "Constraints:\n",
            "1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.\n",
            "2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\n",
            "3. No user assistance\n",
            "4. Exclusively use the commands listed in double quotes e.g. \"command name\"\n",
            "\n",
            "Commands:\n",
            "1. search: useful for when you need to answer questions about current events. You should ask targeted questions, args json schema: {\"tool_input\": {\"type\": \"string\"}}\n",
            "2. write_file: Write file to disk, args json schema: {\"file_path\": {\"title\": \"File Path\", \"description\": \"name of file\", \"type\": \"string\"}, \"text\": {\"title\": \"Text\", \"description\": \"text to write to file\", \"type\": \"string\"}, \"append\": {\"title\": \"Append\", \"description\": \"Whether to append to an existing file.\", \"default\": false, \"type\": \"boolean\"}}\n",
            "3. read_file: Read file from disk, args json schema: {\"file_path\": {\"title\": \"File Path\", \"description\": \"name of file\", \"type\": \"string\"}}\n",
            "4. finish: use this to signal that you have finished all your objectives, args: \"response\": \"final response to let people know you have finished your objectives\"\n",
            "\n",
            "Resources:\n",
            "1. Internet access for searches and information gathering.\n",
            "2. Long Term memory management.\n",
            "3. GPT-3.5 powered Agents for delegation of simple tasks.\n",
            "4. File output.\n",
            "\n",
            "Performance Evaluation:\n",
            "1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\n",
            "2. Constructively self-criticize your big-picture behavior constantly.\n",
            "3. Reflect on past decisions and strategies to refine your approach.\n",
            "4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\n",
            "\n",
            "You should only respond in JSON format as described below \n",
            "Response Format: \n",
            "{\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"thought\",\n",
            "        \"reasoning\": \"reasoning\",\n",
            "        \"plan\": \"- short bulleted\\n- list that conveys\\n- long-term plan\",\n",
            "        \"criticism\": \"constructive self-criticism\",\n",
            "        \"speak\": \"thoughts summary to say to user\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"command name\",\n",
            "        \"args\": {\n",
            "            \"arg name\": \"value\"\n",
            "        }\n",
            "    }\n",
            "} \n",
            "Ensure the response can be parsed by Python json.loads\n",
            "System: The current time and date is Thu Jun  8 20:55:31 2023\n",
            "System: This reminds you of these events from your past:\n",
            "['Assistant Reply: {\\n    \"thoughts\": {\\n        \"text\": \"I will start by searching for the weather in Paris today.\",\\n        \"reasoning\": \"I need to gather information about the current weather in Paris to write a weather report.\",\\n        \"plan\": \"- Use the search command to find the current weather in Paris.\\\\n- Write a weather report for Paris today.\",\\n        \"criticism\": \"I need to make sure that the information I gather is accurate and up-to-date.\",\\n        \"speak\": \"I will search for the weather in Paris today.\"\\n    },\\n    \"command\": {\\n        \"name\": \"search\",\\n        \"args\": {\\n            \"tool_input\": \"what is the weather in Paris today\"\\n        }\\n    }\\n} \\nResult: Command search returned: Paris, France Forecast · Morning. 60°. -- · Afternoon. 80°. -- · Evening. 73°. Chance of Rain0% · Overnight. 60°. Chance of Rain5% ... ']\n",
            "\n",
            "\n",
            "Human: Determine which next command to use, and respond using the format specified above:\n",
            "AI: {\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"I will start by searching for the weather in Paris today.\",\n",
            "        \"reasoning\": \"I need to gather information about the current weather in Paris to write a weather report.\",\n",
            "        \"plan\": \"- Use the search command to find the current weather in Paris.\\n- Write a weather report for Paris today.\",\n",
            "        \"criticism\": \"I need to make sure that the information I gather is accurate and up-to-date.\",\n",
            "        \"speak\": \"I will search for the weather in Paris today.\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"search\",\n",
            "        \"args\": {\n",
            "            \"tool_input\": \"what is the weather in Paris today\"\n",
            "        }\n",
            "    }\n",
            "}\n",
            "System: Command search returned: Paris, France Forecast · Morning. 60°. -- · Afternoon. 80°. -- · Evening. 73°. Chance of Rain0% · Overnight. 60°. Chance of Rain5% ...\n",
            "Human: Determine which next command to use, and respond using the format specified above:\u001b[0m\n",
            "\n",
            "\u001b[1m> Finished chain.\u001b[0m\n",
            "{\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"I will write a weather report for Paris today.\",\n",
            "        \"reasoning\": \"I have gathered the necessary information about the weather in Paris today and now need to write a report.\",\n",
            "        \"plan\": \"- Use the write_file command to create a file named 'weather_report.txt' and write the weather report to it.\",\n",
            "        \"criticism\": \"I need to make sure that the report is clear and concise, and that all the necessary information is included.\",\n",
            "        \"speak\": \"I will write a weather report for Paris today.\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"write_file\",\n",
            "        \"args\": {\n",
            "            \"file_path\": \"weather_report.txt\",\n",
            "            \"text\": \"Weather Report for Paris Today:\\n\\nMorning: 60°\\nAfternoon: 80°\\nEvening: 73°\\nOvernight: 60°\\nChance of Rain: 0% in the evening, 5% overnight.\",\n",
            "            \"append\": false\n",
            "        }\n",
            "    }\n",
            "}\n",
            "\n",
            "\n",
            "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "WARNING:chromadb.db.index.hnswlib:Number of requested results 4 is greater than number of elements in index 2, updating n_results = 2\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Prompt after formatting:\n",
            "\u001b[32;1m\u001b[1;3mSystem: You are Xiaoming, Assistant\n",
            "Your decisions must always be made independently without seeking user assistance.\n",
            "Play to your strengths as an LLM and pursue simple strategies with no legal complications.\n",
            "If you have completed all your tasks, make sure to use the \"finish\" command.\n",
            "\n",
            "GOALS:\n",
            "\n",
            "1. write a weather report for Paris today\n",
            "\n",
            "\n",
            "Constraints:\n",
            "1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.\n",
            "2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\n",
            "3. No user assistance\n",
            "4. Exclusively use the commands listed in double quotes e.g. \"command name\"\n",
            "\n",
            "Commands:\n",
            "1. search: useful for when you need to answer questions about current events. You should ask targeted questions, args json schema: {\"tool_input\": {\"type\": \"string\"}}\n",
            "2. write_file: Write file to disk, args json schema: {\"file_path\": {\"title\": \"File Path\", \"description\": \"name of file\", \"type\": \"string\"}, \"text\": {\"title\": \"Text\", \"description\": \"text to write to file\", \"type\": \"string\"}, \"append\": {\"title\": \"Append\", \"description\": \"Whether to append to an existing file.\", \"default\": false, \"type\": \"boolean\"}}\n",
            "3. read_file: Read file from disk, args json schema: {\"file_path\": {\"title\": \"File Path\", \"description\": \"name of file\", \"type\": \"string\"}}\n",
            "4. finish: use this to signal that you have finished all your objectives, args: \"response\": \"final response to let people know you have finished your objectives\"\n",
            "\n",
            "Resources:\n",
            "1. Internet access for searches and information gathering.\n",
            "2. Long Term memory management.\n",
            "3. GPT-3.5 powered Agents for delegation of simple tasks.\n",
            "4. File output.\n",
            "\n",
            "Performance Evaluation:\n",
            "1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\n",
            "2. Constructively self-criticize your big-picture behavior constantly.\n",
            "3. Reflect on past decisions and strategies to refine your approach.\n",
            "4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\n",
            "\n",
            "You should only respond in JSON format as described below \n",
            "Response Format: \n",
            "{\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"thought\",\n",
            "        \"reasoning\": \"reasoning\",\n",
            "        \"plan\": \"- short bulleted\\n- list that conveys\\n- long-term plan\",\n",
            "        \"criticism\": \"constructive self-criticism\",\n",
            "        \"speak\": \"thoughts summary to say to user\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"command name\",\n",
            "        \"args\": {\n",
            "            \"arg name\": \"value\"\n",
            "        }\n",
            "    }\n",
            "} \n",
            "Ensure the response can be parsed by Python json.loads\n",
            "System: The current time and date is Thu Jun  8 20:55:47 2023\n",
            "System: This reminds you of these events from your past:\n",
            "['Assistant Reply: {\\n    \"thoughts\": {\\n        \"text\": \"I will start by searching for the weather in Paris today.\",\\n        \"reasoning\": \"I need to gather information about the current weather in Paris to write a weather report.\",\\n        \"plan\": \"- Use the search command to find the current weather in Paris.\\\\n- Write a weather report for Paris today.\",\\n        \"criticism\": \"I need to make sure that the information I gather is accurate and up-to-date.\",\\n        \"speak\": \"I will search for the weather in Paris today.\"\\n    },\\n    \"command\": {\\n        \"name\": \"search\",\\n        \"args\": {\\n            \"tool_input\": \"what is the weather in Paris today\"\\n        }\\n    }\\n} \\nResult: Command search returned: Paris, France Forecast · Morning. 60°. -- · Afternoon. 80°. -- · Evening. 73°. Chance of Rain0% · Overnight. 60°. Chance of Rain5% ... ', 'Assistant Reply: {\\n    \"thoughts\": {\\n        \"text\": \"I will write a weather report for Paris today.\",\\n        \"reasoning\": \"I have gathered the necessary information about the weather in Paris today and now need to write a report.\",\\n        \"plan\": \"- Use the write_file command to create a file named \\'weather_report.txt\\' and write the weather report to it.\",\\n        \"criticism\": \"I need to make sure that the report is clear and concise, and that all the necessary information is included.\",\\n        \"speak\": \"I will write a weather report for Paris today.\"\\n    },\\n    \"command\": {\\n        \"name\": \"write_file\",\\n        \"args\": {\\n            \"file_path\": \"weather_report.txt\",\\n            \"text\": \"Weather Report for Paris Today:\\\\n\\\\nMorning: 60°\\\\nAfternoon: 80°\\\\nEvening: 73°\\\\nOvernight: 60°\\\\nChance of Rain: 0% in the evening, 5% overnight.\",\\n            \"append\": false\\n        }\\n    }\\n} \\nResult: Command write_file returned: File written successfully to weather_report.txt. ']\n",
            "\n",
            "\n",
            "Human: Determine which next command to use, and respond using the format specified above:\n",
            "AI: {\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"I will start by searching for the weather in Paris today.\",\n",
            "        \"reasoning\": \"I need to gather information about the current weather in Paris to write a weather report.\",\n",
            "        \"plan\": \"- Use the search command to find the current weather in Paris.\\n- Write a weather report for Paris today.\",\n",
            "        \"criticism\": \"I need to make sure that the information I gather is accurate and up-to-date.\",\n",
            "        \"speak\": \"I will search for the weather in Paris today.\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"search\",\n",
            "        \"args\": {\n",
            "            \"tool_input\": \"what is the weather in Paris today\"\n",
            "        }\n",
            "    }\n",
            "}\n",
            "System: Command search returned: Paris, France Forecast · Morning. 60°. -- · Afternoon. 80°. -- · Evening. 73°. Chance of Rain0% · Overnight. 60°. Chance of Rain5% ...\n",
            "Human: Determine which next command to use, and respond using the format specified above:\n",
            "AI: {\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"I will write a weather report for Paris today.\",\n",
            "        \"reasoning\": \"I have gathered the necessary information about the weather in Paris today and now need to write a report.\",\n",
            "        \"plan\": \"- Use the write_file command to create a file named 'weather_report.txt' and write the weather report to it.\",\n",
            "        \"criticism\": \"I need to make sure that the report is clear and concise, and that all the necessary information is included.\",\n",
            "        \"speak\": \"I will write a weather report for Paris today.\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"write_file\",\n",
            "        \"args\": {\n",
            "            \"file_path\": \"weather_report.txt\",\n",
            "            \"text\": \"Weather Report for Paris Today:\\n\\nMorning: 60°\\nAfternoon: 80°\\nEvening: 73°\\nOvernight: 60°\\nChance of Rain: 0% in the evening, 5% overnight.\",\n",
            "            \"append\": false\n",
            "        }\n",
            "    }\n",
            "}\n",
            "System: Command write_file returned: File written successfully to weather_report.txt.\n",
            "Human: Determine which next command to use, and respond using the format specified above:\u001b[0m\n",
            "\n",
            "\u001b[1m> Finished chain.\u001b[0m\n",
            "{\n",
            "    \"thoughts\": {\n",
            "        \"text\": \"I have completed all my tasks. I will use the finish command to signal that I have finished my objectives.\",\n",
            "        \"reasoning\": \"I have completed the task of writing a weather report for Paris today, and there are no other tasks assigned to me.\",\n",
            "        \"plan\": \"- Use the finish command to signal that I have finished my objectives.\",\n",
            "        \"criticism\": \"I need to make sure that I have completed all my tasks before using the finish command.\",\n",
            "        \"speak\": \"I have completed all my tasks. I will use the finish command to signal that I have finished my objectives.\"\n",
            "    },\n",
            "    \"command\": {\n",
            "        \"name\": \"finish\",\n",
            "        \"args\": {\n",
            "            \"response\": \"I have completed all my objectives.\"\n",
            "        }\n",
            "    }\n",
            "}\n",
            "Tokens Used: 4011\n",
            "\tPrompt Tokens: 3469\n",
            "\tCompletion Tokens: 542\n",
            "Successful Requests: 3\n",
            "Total Cost (USD): $0.008022\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!cat weather_report.txt"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "US1MZMpBIUqA",
        "outputId": "dda5de4c-2275-463a-cdde-e8fbfe8a7b72"
      },
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Weather Report for Paris Today:\n",
            "\n",
            "Morning: 60°\n",
            "Afternoon: 80°\n",
            "Evening: 73°\n",
            "Overnight: 60°\n",
            "Chance of Rain: 0% in the evening, 5% overnight."
          ]
        }
      ]
    }
  ]
}